package com.tiantianfresh.view.controller;

import com.tiantianfresh.model.pojo.AJAXResult;
import com.tiantianfresh.model.pojo.Order;
import com.tiantianfresh.model.pojo.OrderSpecific;
import com.tiantianfresh.model.pojo.OrderState;
import com.tiantianfresh.view.service.ShopOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/6 - 下午 14:21
 */
@Controller
@RequestMapping("/shoporder")
public class ShopOrderController {
    @Autowired
    private ShopOrderService shopOrderService;

    @ResponseBody
    @RequestMapping("/queryShopOrder")
    public Object queryShopOrder(Integer userid){
        AJAXResult result = new AJAXResult();
        List<Order> orders = shopOrderService.queryShopOrder(userid);

       if (orders!=null){
           result.setData(orders);
           result.setSuccess(true);
       }else {
           result.setSuccess(false);
       }
        return result;
    }

    @ResponseBody
    @RequestMapping("/receiving")
    public Object receiving(String orderid){
        AJAXResult result = new AJAXResult();
        Map<String,Object> map = new HashMap<>();
        map.put("orderid",orderid);
        result.setSuccess(shopOrderService.receiving(map));
        return result;
    }

    @ResponseBody
    @RequestMapping("/queryOrderStateAll")
    public Object queryOrderStateAll(){
        AJAXResult result = new AJAXResult();
        List<OrderState> orderStates = shopOrderService.queryOrderStateAll();
        orderStates.forEach(OrderState-> System.out.println("OrderState----->"+OrderState));
        if (orderStates != null) {
            result.setData(orderStates);
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
}
